<layout:basic/>

<section class="content">
    <div class="row">
        <!-- left column -->
        <div class="col-md-12">
            <!-- general form elements -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title"> 修改密码</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form role="form">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="old_pwd">旧的密码</label>
                            <input type="password" class="form-control" id="old_pwd">
                        </div>
                        <div class="form-group">
                            <label for="new_pwd">新的密码</label>
                            <input type="password" class="form-control" id="new_pwd">
                        </div>
                        <div class="form-group">
                            <label for="rpt_pwd">重复新密码</label>
                            <input type="password" class="form-control" id="rpt_pwd">
                            <p class="help-block">.</p>
                        </div>
                    </div>
                    <!-- /.box-body -->

                    <div class="box-footer">
                        <button type="button" id="save_pwd" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
            <!-- /.box -->

        </div>
        <!--/.col (right) -->
    </div>
    <!-- /.row -->
</section>

<script>

    $("#save_pwd").click(function () {
        var old_pwd = $("#old_pwd");
        var new_pwd = $("#new_pwd");
        var rpt_pwd = $("#rpt_pwd");
        if (!old_pwd.val().trim()) {
            return isea.notify.show('旧的密码不能为空');
        }
        if (!new_pwd.val().trim()) {
            return isea.notify.show('新的密码不能为空');
        }
        if (new_pwd.val() !== rpt_pwd.val()) {
            return isea.notify.show('密码前后不一致');
        }

        $.get("__PUBLIC__/admin/user/changepassword", {
            old_pwd: old_pwd.val(),
            new_pwd: new_pwd.val()
        }, function (data) {
            if (data.status) {
                location.href = "__PUBLIC__/admin/sign/out";
            } else {
                return isea.notify.show(data.message);
            }
        });

    });
</script>